package com.ffcs.cn.action.common;

import com.supermap.desktop.core.utilties.ListUtilities;

import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;
import java.util.List;

/**
 * 打开地图、场景、布局面板的表格数据模型
 *
  */
public abstract class FormModel extends DefaultTableModel {

	// 存储表格数据的数组
	private final List<Object> rowData = new ArrayList<>();

	public int getRowCount() {
		return rowData == null ? 0 : rowData.size();
	}

	@Override
	public abstract Object getValueAt(int row, int column);

	@Override
	public abstract int getColumnCount();

	@Override
	public abstract String getColumnName(int column);

	@Override
	public boolean isCellEditable(int row, int column) {
		return false;
	}

	public void add(Object rowData) {
		this.rowData.add(rowData);
		fireTableDataChanged();
	}

	public List<Object> getData() {
		return ListUtilities.listCopy(rowData);
	}

	public Object get(int row) {
		return rowData.get(row);
	}

	public boolean contains(Object obj) {
		return rowData.contains(obj);
	}

	public void remove(int[] rows) {
		if (rows.length > 0) {
			for (int i = rows.length - 1; i >= 0; i--) {
				rowData.remove(rows[i]);
			}
			fireTableDataChanged();
		}
	}
}
